<template>
	<view class="container">
		<!-- 顶部说明 -->
		<view class="header-tip">
			<text class="tip-icon">✨</text>
			<view class="tip-content">
				<text class="tip-title">提升您的接单率</text>
				<text class="tip-desc">完善资料和认证可让宠物主人更信任您</text>
			</view>
		</view>

		<!-- 进度指示 -->
		<view class="progress-bar">
			<view class="progress-item" :class="{active: step >= 1, completed: step > 1}">
				<view class="progress-dot">1</view>
				<text class="progress-text">基础信息</text>
			</view>
			<view class="progress-line" :class="{active: step > 1}"></view>
			<view class="progress-item" :class="{active: step >= 2, completed: step > 2}">
				<view class="progress-dot">2</view>
				<text class="progress-text">经验证明</text>
			</view>
			<view class="progress-line" :class="{active: step > 2}"></view>
			<view class="progress-item" :class="{active: step >= 3}">
				<view class="progress-dot">3</view>
				<text class="progress-text">完成认证</text>
			</view>
		</view>

		<!-- 步骤1：基础信息 -->
		<view class="form-section" v-if="step === 1">
			<view class="section-title">基础信息</view>
			
			<view class="form-item">
				<text class="label">真实姓名 <text class="required">*</text></text>
				<input class="input" v-model="formData.name" placeholder="请输入真实姓名" />
			</view>

			<view class="form-item">
				<text class="label">身份证号 <text class="required">*</text></text>
				<input class="input" v-model="formData.idCard" placeholder="请输入身份证号" maxlength="18" />
			</view>

			<view class="form-item">
				<text class="label">所在城市 <text class="required">*</text></text>
				<input class="input" v-model="formData.city" placeholder="请选择所在城市" @click="selectCity" />
			</view>

			<view class="form-item">
				<text class="label">服务区域</text>
				<input class="input" v-model="formData.serviceArea" placeholder="如：朝阳区、海淀区" />
			</view>

			<view class="form-item">
				<text class="label">自我介绍</text>
				<textarea 
					class="textarea" 
					v-model="formData.intro" 
					placeholder="简单介绍您的宠物护理经验，让主人更了解您"
					maxlength="200" />
				<text class="char-count">{{formData.intro.length}}/200</text>
			</view>
		</view>

		<!-- 步骤2：经验证明（可选） -->
		<view class="form-section" v-if="step === 2">
			<view class="section-title">
				<text>经验证明</text>
				<text class="optional-tag">选填</text>
			</view>
			
			<view class="tip-box">
				<text class="tip-icon-small">💡</text>
				<text class="tip-text-small">上传相关证书或案例照片可大幅提升接单率</text>
			</view>

			<!-- 养宠经验 -->
			<view class="form-item">
				<text class="label">养宠经验（年）</text>
				<uni-data-select 
					v-model="formData.experience" 
					:localdata="experienceOptions"
					placeholder="请选择"
					class="select-input">
				</uni-data-select>
			</view>

			<!-- 擅长宠物类型 -->
			<view class="form-item">
				<text class="label">擅长照顾的宠物</text>
				<view class="tag-group">
					<view 
						class="tag-item" 
						:class="{active: formData.petTypes.includes(type.value)}"
						v-for="type in petTypeOptions" 
						:key="type.value"
						@click="togglePetType(type.value)">
						<text class="tag-icon">{{type.icon}}</text>
						<text class="tag-name">{{type.text}}</text>
					</view>
				</view>
			</view>

			<!-- 证书上传 -->
			<view class="form-item">
				<text class="label">相关证书（如有）</text>
				<view class="upload-area">
					<view class="upload-item" v-for="(img, index) in formData.certificates" :key="index">
						<image class="upload-img" :src="img" mode="aspectFill"></image>
						<view class="delete-btn" @click="deleteCertificate(index)">×</view>
					</view>
					<view class="upload-btn" @click="uploadCertificate" v-if="formData.certificates.length < 3">
						<text class="upload-icon">+</text>
						<text class="upload-text">上传证书</text>
					</view>
				</view>
				<text class="upload-tip">最多上传3张，支持宠物护理、急救等相关证书</text>
			</view>

			<!-- 案例照片 -->
			<view class="form-item">
				<text class="label">服务案例（如有）</text>
				<view class="upload-area">
					<view class="upload-item" v-for="(img, index) in formData.cases" :key="index">
						<image class="upload-img" :src="img" mode="aspectFill"></image>
						<view class="delete-btn" @click="deleteCase(index)">×</view>
					</view>
					<view class="upload-btn" @click="uploadCase" v-if="formData.cases.length < 6">
						<text class="upload-icon">+</text>
						<text class="upload-text">上传照片</text>
					</view>
				</view>
				<text class="upload-tip">最多上传6张，展示您与宠物的温馨瞬间</text>
			</view>
		</view>

		<!-- 步骤3：完成 -->
		<view class="success-section" v-if="step === 3">
			<text class="success-icon">🎉</text>
			<text class="success-title">资料提交成功</text>
			<text class="success-desc">您可以立即开始接单啦！</text>
			<text class="success-tip">完善的资料可以提升您的接单率哦</text>
		</view>

		<!-- 底部按钮 -->
		<view class="bottom-actions">
			<button class="skip-btn" @click="skipCertification" v-if="step < 3">
				{{ step === 1 ? '跳过认证，直接接单' : '跳过' }}
			</button>
			<button class="next-btn" @click="nextStep">
				{{ step === 1 ? '下一步' : step === 2 ? '提交' : '开始接单' }}
			</button>
		</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			step: 1,
			formData: {
				name: '',
				idCard: '',
				city: '',
				serviceArea: '',
				intro: '',
				experience: 0,
				petTypes: [],
				certificates: [],
				cases: []
			},
			experienceOptions: [
				{value: 0, text: '无经验'},
				{value: 1, text: '1年以下'},
				{value: 2, text: '1-3年'},
				{value: 3, text: '3-5年'},
				{value: 4, text: '5年以上'}
			],
			petTypeOptions: [
				{value: 'cat', text: '猫咪', icon: '🐱'},
				{value: 'dog', text: '狗狗', icon: '🐕'},
				{value: 'bird', text: '鸟类', icon: '🐦'},
				{value: 'other', text: '其他', icon: '🐾'}
			]
		}
	},
	methods: {
		// 选择城市
		selectCity() {
			// 实际项目中应使用城市选择器
			uni.showToast({
				title: '城市选择功能开发中',
				icon: 'none'
			})
		},

		// 切换宠物类型
		togglePetType(type) {
			const index = this.formData.petTypes.indexOf(type)
			if (index > -1) {
				this.formData.petTypes.splice(index, 1)
			} else {
				this.formData.petTypes.push(type)
			}
		},

		// 上传证书
		uploadCertificate() {
			uni.chooseImage({
				count: 3 - this.formData.certificates.length,
				success: (res) => {
					this.formData.certificates = [...this.formData.certificates, ...res.tempFilePaths]
				}
			})
		},

		// 删除证书
		deleteCertificate(index) {
			this.formData.certificates.splice(index, 1)
		},

		// 上传案例
		uploadCase() {
			uni.chooseImage({
				count: 6 - this.formData.cases.length,
				success: (res) => {
					this.formData.cases = [...this.formData.cases, ...res.tempFilePaths]
				}
			})
		},

		// 删除案例
		deleteCase(index) {
			this.formData.cases.splice(index, 1)
		},

		// 跳过认证
		skipCertification() {
			uni.showModal({
				title: '温馨提示',
				content: '跳过认证可能会影响您的接单率，确定要跳过吗？',
				success: (res) => {
					if (res.confirm) {
						this.goToHome()
					}
				}
			})
		},

		// 下一步
		nextStep() {
			if (this.step === 1) {
				// 验证基础信息
				if (!this.formData.name) {
					uni.showToast({ title: '请输入姓名', icon: 'none' })
					return
				}
				if (!this.formData.idCard) {
					uni.showToast({ title: '请输入身份证号', icon: 'none' })
					return
				}
				if (!this.formData.city) {
					uni.showToast({ title: '请选择所在城市', icon: 'none' })
					return
				}
				this.step = 2
			} else if (this.step === 2) {
				// 提交认证
				uni.showLoading({ title: '提交中...' })
				setTimeout(() => {
					uni.hideLoading()
					this.step = 3
				}, 1500)
			} else {
				this.goToHome()
			}
		},

		// 前往首页
		goToHome() {
			uni.switchTab({
				url: '/pages/index/index'
			})
		}
	}
}
</script>

<style scoped>
.container {
	min-height: 100vh;
	background: linear-gradient(135deg, #F0F8FF 0%, #FFF0F5 100%);
	padding: 30rpx;
	padding-bottom: 200rpx;
}

/* 顶部提示 */
.header-tip {
	display: flex;
	align-items: center;
	background: linear-gradient(135deg, #FFF8DC 0%, #FFE4B5 100%);
	border-radius: 24rpx;
	padding: 30rpx;
	margin-bottom: 40rpx;
	box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}

.tip-icon {
	font-size: 48rpx;
	margin-right: 20rpx;
}

.tip-content {
	flex: 1;
}

.tip-title {
	font-size: 30rpx;
	font-weight: 600;
	color: #333333;
	display: block;
	margin-bottom: 8rpx;
}

.tip-desc {
	font-size: 24rpx;
	color: #666666;
}

/* 进度条 */
.progress-bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin-bottom: 50rpx;
	padding: 0 20rpx;
}

.progress-item {
	display: flex;
	flex-direction: column;
	align-items: center;
}

.progress-dot {
	width: 60rpx;
	height: 60rpx;
	border-radius: 50%;
	background: #E0E0E0;
	color: #999999;
	font-size: 26rpx;
	font-weight: 600;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-bottom: 10rpx;
	transition: all 0.3s ease;
}

.progress-item.active .progress-dot {
	background: linear-gradient(135deg, #FFB6C1 0%, #FF91A4 100%);
	color: #FFFFFF;
}

.progress-item.completed .progress-dot {
	background: #98E4D6;
}

.progress-text {
	font-size: 22rpx;
	color: #999999;
}

.progress-item.active .progress-text {
	color: #FFB6C1;
	font-weight: 600;
}

.progress-line {
	flex: 1;
	height: 4rpx;
	background: #E0E0E0;
	margin: 0 10rpx;
	margin-bottom: 30rpx;
}

.progress-line.active {
	background: #98E4D6;
}

/* 表单区域 */
.form-section {
	background: #FFFFFF;
	border-radius: 24rpx;
	padding: 40rpx 30rpx;
	box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.08);
}

.section-title {
	font-size: 32rpx;
	font-weight: 700;
	color: #333333;
	margin-bottom: 30rpx;
	display: flex;
	align-items: center;
	justify-content: space-between;
}

.optional-tag {
	font-size: 22rpx;
	color: #FF8C42;
	background: rgba(255, 140, 66, 0.1);
	padding: 5rpx 15rpx;
	border-radius: 20rpx;
}

.tip-box {
	display: flex;
	align-items: center;
	background: rgba(152, 228, 214, 0.1);
	border-radius: 20rpx;
	padding: 20rpx;
	margin-bottom: 30rpx;
}

.tip-icon-small {
	font-size: 28rpx;
	margin-right: 10rpx;
}

.tip-text-small {
	font-size: 24rpx;
	color: #666666;
	flex: 1;
}

.form-item {
	margin-bottom: 30rpx;
}

.label {
	font-size: 28rpx;
	color: #333333;
	font-weight: 600;
	display: block;
	margin-bottom: 15rpx;
}

.required {
	color: #FF4444;
}

.input, .select-input {
	width: 100%;
	height: 80rpx;
	background: #F5F5F5;
	border-radius: 20rpx;
	padding: 0 25rpx;
	font-size: 28rpx;
	border: 2rpx solid transparent;
}

.textarea {
	width: 100%;
	min-height: 180rpx;
	background: #F5F5F5;
	border-radius: 20rpx;
	padding: 20rpx 25rpx;
	font-size: 28rpx;
	border: 2rpx solid transparent;
}

.char-count {
	font-size: 22rpx;
	color: #999999;
	text-align: right;
	display: block;
	margin-top: 10rpx;
}

/* 标签组 */
.tag-group {
	display: flex;
	flex-wrap: wrap;
	gap: 20rpx;
}

.tag-item {
	display: flex;
	align-items: center;
	padding: 15rpx 30rpx;
	background: #F5F5F5;
	border-radius: 30rpx;
	border: 2rpx solid transparent;
}

.tag-item.active {
	background: rgba(255, 182, 193, 0.2);
	border-color: #FFB6C1;
}

.tag-icon {
	font-size: 28rpx;
	margin-right: 8rpx;
}

.tag-name {
	font-size: 26rpx;
	color: #666666;
}

.tag-item.active .tag-name {
	color: #FFB6C1;
	font-weight: 600;
}

/* 上传区域 */
.upload-area {
	display: flex;
	flex-wrap: wrap;
	gap: 20rpx;
	margin-bottom: 15rpx;
}

.upload-item {
	width: 200rpx;
	height: 200rpx;
	position: relative;
}

.upload-img {
	width: 100%;
	height: 100%;
	border-radius: 20rpx;
}

.delete-btn {
	position: absolute;
	top: -10rpx;
	right: -10rpx;
	width: 40rpx;
	height: 40rpx;
	background: #FF4444;
	color: #FFFFFF;
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 30rpx;
}

.upload-btn {
	width: 200rpx;
	height: 200rpx;
	background: #F5F5F5;
	border-radius: 20rpx;
	border: 2rpx dashed #CCCCCC;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.upload-icon {
	font-size: 48rpx;
	color: #CCCCCC;
	margin-bottom: 10rpx;
}

.upload-text {
	font-size: 24rpx;
	color: #999999;
}

.upload-tip {
	font-size: 22rpx;
	color: #999999;
}

/* 成功页面 */
.success-section {
	text-align: center;
	padding: 100rpx 40rpx;
}

.success-icon {
	font-size: 120rpx;
	display: block;
	margin-bottom: 30rpx;
}

.success-title {
	font-size: 36rpx;
	font-weight: 700;
	color: #333333;
	display: block;
	margin-bottom: 20rpx;
}

.success-desc {
	font-size: 28rpx;
	color: #666666;
	display: block;
	margin-bottom: 40rpx;
}

.success-tip {
	font-size: 24rpx;
	color: #FF8C42;
	background: rgba(255, 140, 66, 0.1);
	padding: 15rpx 30rpx;
	border-radius: 30rpx;
	display: inline-block;
}

/* 底部按钮 */
.bottom-actions {
	position: fixed;
	bottom: 0;
	left: 0;
	right: 0;
	background: #FFFFFF;
	padding: 20rpx 30rpx;
	padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
	box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.08);
	display: flex;
	gap: 20rpx;
}

.skip-btn {
	flex: 1;
	height: 90rpx;
	background: #F5F5F5;
	color: #666666;
	border-radius: 24rpx;
	font-size: 28rpx;
	font-weight: 600;
	border: none;
}

.next-btn {
	flex: 2;
	height: 90rpx;
	background: linear-gradient(135deg, #FFB6C1 0%, #FF91A4 100%);
	color: #FFFFFF;
	border-radius: 24rpx;
	font-size: 28rpx;
	font-weight: 700;
	border: none;
}
</style>
